package com.zhxy;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@SpringBootApplication
@MapperScan(basePackages = {"com.zhxy.mapper"})
public class ZhxyApplication {
    public static void main(String[] args) {
        SpringApplication.run(ZhxyApplication.class);
    }

    @Bean
    public MybatisPlusInterceptor getMybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor=new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));

        return mybatisPlusInterceptor;
    }
    @Bean
    public BCryptPasswordEncoder getBCryptPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory){
        //创建一个模板对象，通过工厂对象来创建
        RedisTemplate<String,Object> template = new  RedisTemplate<String,Object>();
        template.setConnectionFactory(factory);
        //key采用String类型转换器
        template.setKeySerializer(new StringRedisSerializer());
        //hash的key使用String类型转换器
        template.setHashKeySerializer(new StringRedisSerializer());
        //Value的类型转换器
        template.setValueSerializer(new Jackson2JsonRedisSerializer(Object.class));
        //hash的value类型转换器
        template.setHashValueSerializer(new Jackson2JsonRedisSerializer(Object.class));
        return template;
    }

}
